package ebj.common.queue.request.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang.StringUtils;

import com.google.gson.Gson;

import ebj.common.queue.meta.QueryEntry;

public class QueryQueue {
    public static ArrayBlockingQueue<QueryEntry> queue = null;
    private static AtomicInteger count = new AtomicInteger();
    static{
        queue = new ArrayBlockingQueue<QueryEntry>(10);
    }
    
    private static QueryEntry queryEntry = null;
    
    public QueryQueue() {}
    public QueryQueue(QueryEntry queryEntry) {
        this.queryEntry = queryEntry;
    }

    public static void addQuery(String query) {
        if (StringUtils.isNotBlank(query)) {
            queryEntry = new QueryEntry("key_md5_tmp " + count.incrementAndGet(), query);
            if (!queue.offer(queryEntry)) {
                System.out.println("队列已满，生产者...暂不处理.");
            }else {
                System.out.println("查询已入队列：" + new Gson().toJson(queryEntry));
            }
        }
        
    }
}
